/**
 * 
 */
package derby;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;

import com.cwnuzj.ffms.db.JdbcUtil;

/**
 * @author Jeff Zheng
 * 
 */
public class DerbyTest {

	private Connection connect = null;
	private Statement statement = null;
	private ResultSet resultSet = null;

	public DerbyTest() throws Exception {
		try {
			close();
//			Class.forName("org.apache.derby.jdbc.ClientDriver").newInstance();
//			Class.forName("org.apache.derby.jdbc.EmbeddedDriver").newInstance();
//			connect = DriverManager.getConnection("jdbc:derby:D:/eclipse-rcp-indigo-win32/workspace/my-ffms/com.cwnuzj.ffms.db/ffmsdb;user=ffmsdb;password=ffmsdb");
			Connection connect=JdbcUtil.getConnection();
			PreparedStatement statement = connect.prepareStatement("SELECT * from ffms.t_user");

			resultSet = statement.executeQuery();
			while (resultSet.next()) {
				String user = resultSet.getString("username");
				String pwd = resultSet.getString("password");
				System.out.println("User: " + user);
				System.out.println("ID: " + pwd);
			}
		} catch (Exception e) {
			throw e;
		} finally {
			close();
		}

	}

	private void close() {
		try {
			if (resultSet != null) {
				resultSet.close();
			}
			if (statement != null) {
				statement.close();
			}
			if (connect != null) {
				connect.close();
			}
		} catch (Exception e) {

		}
	}

	public static void main(String[] args) throws Exception {
		DerbyTest dao = new DerbyTest();
	}

}
